var e = require;
var t = module;
var o,
    n = (o = e("Platform")) && o.__esModule ? o : {default: o};
cc.Class({
    extends: cc.Component,
    properties: {
        nativePbg: cc.Node,
        nativeYinSiZhengCe: cc.Node,
        nativeYongHuXieYi: cc.Node,
        nativeGuide: cc.Node,
        shiLingTiShi: cc.Node,
        geBaoFa: cc.Node,
        enterBtn: cc.Node,
        agreeBtn: cc.Node,
        noAgreeBtn: cc.Node,
        closeBtn: cc.Node,
        labelYinSi: cc.Label,
        labelXieYi: cc.Label,
        gameName: "",
        companyName: ""
    },
    onLoad: function onLoad() {
        var e = this;
        if ((window.lplatform || new n.default(), window.lplatform)) {
            if (((this.pbg = this.nativePbg), "web" == lplatform.channel));
            else if (
                lplatform.channel != CHANNEL.oppo &&
                lplatform.channel != CHANNEL.vivo &&
                lplatform.channel != CHANNEL.qq &&
                lplatform.channel != CHANNEL.android &&
                lplatform.channel != CHANNEL.iOS
            )
                return void (this.node.active = !1);
            (this.closeBtn.active = !1), (this.lsname = "YinSiZhengCeAutoShowed");
            var t = cc.sys.localStorage.getItem(this.lsname);
            if (
                ((this.pbg.active = !1),
                (this.autoShowed = t || !1),
                window.android && (nativeChannel = window.android.getNativeChannel()),
                console.log("nativeChannel:" + nativeChannel),
                "Ohayoo" == nativeChannel)
            ) {
                if (((this.autoShowed = !0), !window.nativeAdInitlized)) {
                    window.nativeAdInitlized = !0;
                    var o = {name: "agreePrivacy", data: {}};
                    (o = JSON.stringify(o)), lplatform.js2NativeEvent(o);
                }
            } else if (!this.autoShowed && this.enterBtn.active)
                this.scheduleOnce(function () {
                    return (e.pbg.active = !0);
                }, 0.2);
            else if (("iOS" == lplatform.channel || "Android" == lplatform.channel) && !window.nativeAdInitlized) {
                window.nativeAdInitlized = !0;
                var i = {name: "agreePrivacy", data: {}};
                (i = JSON.stringify(i)), lplatform.js2NativeEvent(i);
            }
            lplatform.params.onlineCompanyName && (this.companyName = lplatform.params.onlineCompanyName);
            var a = this.replaceString(this.labelYinSi.string, "{游戏名称}", this.gameName);
            (a = this.replaceString(a, "{公司名称}", this.companyName)), (this.labelYinSi.string = a);
            var r = this.replaceString(this.labelXieYi.string, "{游戏名称}", this.gameName);
            (r = this.replaceString(r, "{公司名称}", this.companyName)), (this.labelXieYi.string = r);
        }
    },
    replaceString: function replaceString(e, t, o) {
        var n = e + "";
        if (((o = o || ""), n && t))
            for (;;) {
                var i = t.length,
                    a = n.indexOf(t);
                if (!(a >= 0)) break;
                var r = n.substring(0, a),
                    s = n.substring(a + i);
                n = r + o + s;
            }
        return n;
    },
    onClickAgree: function onClickAgree() {
        if (
            !(
                this.autoShowed ||
                ("iOS" != lplatform.channel && "Android" != lplatform.channel) ||
                window.nativeAdInitlized
            )
        ) {
            window.nativeAdInitlized = !0;
            var e = {name: "agreePrivacy", data: {}};
            (e = JSON.stringify(e)), lplatform.js2NativeEvent(e);
        }
        this.hideYinSi();
    },
    onClickNoAgree: function onClickNoAgree() {
        if (("iOS" == lplatform.channel || "Android" == lplatform.channel) && !window.nativeAdInitlized) {
            window.nativeAdInitlized = !0;
            var e = {name: "agreePrivacy", data: {}};
            (e = JSON.stringify(e)), lplatform.js2NativeEvent(e);
        }
        this.exitApp();
    },
    onClickShow: function onClickShow() {
        if ("Ohayoo" == nativeChannel) {
            var e = {name: "geBaoFa", data: {}};
            (e = JSON.stringify(e)), lplatform.js2NativeEvent(e);
        } else
            (this.pbg.active = !0),
                !this.autoShowed && this.enterBtn.active
                    ? ((this.agreeBtn.active = !0), (this.noAgreeBtn.active = !0), (this.closeBtn.active = !1))
                    : ((this.agreeBtn.active = !1), (this.noAgreeBtn.active = !1), (this.closeBtn.active = !0));
    },
    onClickClose: function onClickClose() {
        this.hideYinSi();
    },
    hideYinSi: function hideYinSi() {
        (this.pbg.active = !1), (this.autoShowed = !0), cc.sys.localStorage.setItem(this.lsname, this.autoShowed);
    },
    exitApp: function exitApp() {
        if (lplatform.labData.mainSwitch && lplatform.labData.privacyAgree && 1 == lplatform.labData.privacyAgree)
            this.hideYinSi();
        else if (window.qg)
            qg.exitApplication({
                success: function success() {},
                complete: function complete() {},
                fail: function fail() {}
            });
        else if (window.qq) qq.exitMiniProgram();
        else if ("iOS" == lplatform.channel || "Android" == lplatform.channel) {
            var e = {name: "exitApp", data: {}};
            (e = JSON.stringify(e)), lplatform.js2NativeEvent(e);
        } else console.error("本渠道退出功能未实现");
    },
    showNativeYinSiZhengCe: function showNativeYinSiZhengCe() {
        (this.nativeGuide.active = !1), (this.nativeYinSiZhengCe.active = !0);
    },
    showNativeYongHuXieYi: function showNativeYongHuXieYi() {
        (this.nativeGuide.active = !1), (this.nativeYongHuXieYi.active = !0);
    },
    hideNativeYinSiZhengCe: function hideNativeYinSiZhengCe() {
        (this.nativeGuide.active = !0), (this.nativeYinSiZhengCe.active = !1);
    },
    hideNativeYongHuXieYi: function hideNativeYongHuXieYi() {
        (this.nativeGuide.active = !0), (this.nativeYongHuXieYi.active = !1);
    },
    onClickGeBaoFa: function onClickGeBaoFa() {
        if ("iOS" == lplatform.channel || "Android" == lplatform.channel) {
            var e = JSON.stringify({name: "geBaoFa", data: {}});
            lplatform.js2NativeEvent(e);
        }
        this.geBaoFa && (this.geBaoFa.active = !0);
    },
    hideGeBaoFa: function hideGeBaoFa() {
        this.geBaoFa && (this.geBaoFa.active = !1);
    },
    onClickShiLingTiShi: function onClickShiLingTiShi() {
        if ("iOS" == lplatform.channel || "Android" == lplatform.channel) {
            var e = JSON.stringify({name: "shiLingTiShi", data: {}});
            lplatform.js2NativeEvent(e);
        }
        this.shiLingTiShi && (this.shiLingTiShi.active = !0);
    },
    hideShiLingTiShi: function hideShiLingTiShi() {
        this.shiLingTiShi && (this.shiLingTiShi.active = !1);
    }
});
